package cn.edu.scau.cmi.linhuanrui.comprehension;

import javafx.fxml.FXML;

import javafx.scene.control.Button;
import javafx.stage.Stage;
import cn.edu.scau.cmi.linhuanrui.client.AbstractFactoryClient;
import cn.edu.scau.cmi.linhuanrui.client.AdapterClient;
import cn.edu.scau.cmi.linhuanrui.client.ConsistentCompositeClient;
import cn.edu.scau.cmi.linhuanrui.client.FactoryClient;
import cn.edu.scau.cmi.linhuanrui.client.HibernateClient;
import cn.edu.scau.cmi.linhuanrui.client.InterProgrammingClient;
import cn.edu.scau.cmi.linhuanrui.client.MultitonClient;
import cn.edu.scau.cmi.linhuanrui.client.SafeCompositeClient;
import cn.edu.scau.cmi.linhuanrui.client.SimpleFactoryMethodClient;
import cn.edu.scau.cmi.linhuanrui.client.SingletonClient;
import cn.edu.scau.cmi.linhuanrui.client.SpringClient;
import cn.edu.scau.cmi.linhuanrui.client.Spring02ApplicationContextClient;
import javafx.event.ActionEvent;

public class ComprehensionController {
	@FXML
	private Button singleton;
	@FXML
	private Button multition;
	@FXML
	private Button interProgrammer;
	@FXML
	private Button simpleFactory;
	@FXML
	private Button factory;
	@FXML
	private Button abstractFactory;
	@FXML
	private Button adapter;
	@FXML
	private Button safeComposite;
	@FXML
	private Button consistentComposite;
	@FXML
	private Button hibernate;
	@FXML
	private Button spring;
	@FXML
	private Button springHibernate;

	// Event Listener on Button[#simpleFactory].onAction
	@FXML
	public void Btn_Click(ActionEvent event) {
		if (event.getSource() == interProgrammer) {
			try {
				InterProgrammingClient interProgrammingClient = new InterProgrammingClient();
				interProgrammingClient.main(null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (event.getSource() == singleton) {
			SingletonClient singletonClient = new SingletonClient();
			singletonClient.start(new Stage());
		} else if (event.getSource() == multition) {
			MultitonClient multitionClient = new MultitonClient();
			multitionClient.start(new Stage());
		} else if (event.getSource() == simpleFactory) {
			try {
				SimpleFactoryMethodClient simpleFactoryMethodClient = new SimpleFactoryMethodClient();
				simpleFactoryMethodClient.start(new Stage());
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (event.getSource() == factory) {
			try {
				FactoryClient factoryClient = new FactoryClient();
				factoryClient.start(new Stage());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else if (event.getSource() == abstractFactory) {
			try {
				AbstractFactoryClient abstractFactoryClient = new AbstractFactoryClient();
				abstractFactoryClient.start(new Stage());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else if (event.getSource() == adapter) {
			AdapterClient adapterClient = new AdapterClient();
			adapterClient.start(new Stage());
		} else if (event.getSource() == safeComposite) {
			SafeCompositeClient safeCompositeClient = new SafeCompositeClient();
			safeCompositeClient.main(null);
		} else if (event.getSource() == consistentComposite) {
			ConsistentCompositeClient consistentCompositeClient = new ConsistentCompositeClient();
			consistentCompositeClient.main(null);
		} else if (event.getSource() == hibernate) {
			HibernateClient hibernateClient = new HibernateClient();
			hibernateClient.start(new Stage());
		} else if (event.getSource() == spring) {
			try {
				Spring02ApplicationContextClient springHibernateClient = new Spring02ApplicationContextClient();
				springHibernateClient.main(null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (event.getSource() == springHibernate) {
			try {
				SpringClient springClient = new SpringClient();
				springClient.start(new Stage());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
